<?php
/**
 * Created by PhpStorm.
 * User: 王松
 * Time: 2017/6/16 14:18
 */

namespace App\Transformers\Reservation;

use App\Models\Reservation\Reservation;
use App\Transformers\NoTransformer;
use Carbon\Carbon;
use Illuminate\Notifications\DatabaseNotification;
use League\Fractal\TransformerAbstract;

class MessageTransformer extends TransformerAbstract
{
    /**
     * @param \Illuminate\Notifications\DatabaseNotification $notification
     * @return array
     */
    public function transform(DatabaseNotification $notification)
    {
        $data = [
            'id'           => $notification->id,
            'user_id'      => $notification->notifiable_id,
            'type'         => $notification->data['type'],
            'source'       => $notification->data['source'],
            'message'      => $notification->data['message'],
            'detail_count' => $notification->data['count'],
            'detail'       => $notification->data['detail'],
            'created_at'   => $notification->created_at->diffForHumans(),
        ];

        if ($notification->read_at) {
            $data['read_at'] = $notification->read_at->toDateTimeString();
        } else {
            $data['read_at'] = Carbon::now()->toDateTimeString();
        }

        return $data;
    }
}